package main

import (
	"fmt"
	"time"
)

func main() {
	chanDemo1()
}

func worker1(id int, c chan int) {
	for {
		fmt.Printf("Worker %d received %d\n",
			id, <-c)
	}
}

func chanDemo1() {
	var c chan int
	fmt.Println(c) // c = nil,nil 没法用

	c1 := make(chan int)

	go worker1(0, c1)

	c1 <- 1 // 向chan 添加数据, 没有上面闭包会造成死锁
	c1 <- 2

	time.Sleep(time.Millisecond) // 不然上面未来得及打印就退出
}
